/* eslint valid-jsdoc: "off" */

'use strict';
const path = require('path')
const fs = require('fs')


/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
    /**
     * built-in config
     * @type {Egg.EggAppConfig}
     **/
    const config = exports = {};

    // use for cookie sign key, should change to your own and keep security
    config.keys = appInfo.name + '_1597544837182_284';

    // add your middleware config here
    config.middleware = ['errorHandler', 'token','xmlParser'];

    // add your user config here
    const userConfig = {
        // myAppName: 'egg',
    };

    config.errorHandler = {
        // enable: true, // 中间件开启配置
        match: '/', // 设置请求中间件的请求路由
        // ignore: '', // 设置不经过这个中间件的请求路由
    };

    config.cluster = {
        listen: {
            port: 8041,
            hostname: '0.0.0.0',
        }
    };

    config.cors = {
        origin: '*',//域名+端口 或者  *(全匹配)
        allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
    };

    config.redis = {
        client: {
            port: 6379,          // Redis port
            host: '127.0.0.1',   // Redis host
            password: '',
            db: 0,
        },
    };


    /*config.amqplib = {
        client: {
            // url: 'amqp://localhost',
            connectOptions: {
                protocol: 'amqp',
                hostname: 'localhost',
                port: 5672,
                username: 'guest',
                password: 'guest',
                // locale: 'en_US',
                // frameMax: 0,
                // heartbeat: 0,
                // vhost: '/',
            },
        }
    };*/


    config.multipart = {
        fileSize: '50mb',
        mode: 'file',
        fileExtensions: ['','.*','.pdf','.doc','.docx','.xls','.xlsx','.accdb','.pptx','.txt'], // 扩展几种上传的文件格式
    };

    config.mail = {
        from: 'verify@ferlive11.cn',
        pwd: 'Finwei2021',
    };


    config.security = {
        csrf: {
            enable: false
        }
    };

    // 覆盖egg自带的配置 使支持接收xml参数
    config.bodyParser = {
        enable: true,
        encoding: 'utf8',
        formLimit: '10mb',
        jsonLimit: '10mb',
        strict: true,
        // @see https://github.com/hapijs/qs/blob/master/lib/parse.js#L8 for more options
        queryString: {
            arrayLimit: 100,
            depth: 5,
            parameterLimit: 1000,
        },
        enableTypes: ['json', 'form', 'text'],
        extendTypes: {
            text: ['text/xml', 'application/xml'],
        },
    };


    config.logger = {
        consoleLevel: 'DEBUG',
        dir: path.join(__dirname, '../logs/'),
    };

    config.mysql = {
        //database configuration
       /* client: {
            //host
            host: '8.218.121.236',
            //port
            port: '13406',
            //username
            user: 'root',
            //password
            password: '1ada1b971c1f5596a7d0b5374c8297886943c90a',
            connectionLimit: 10,
            //database
            database: 'petdb_dev',
            charset: "utf8mb4"
        },*/
        client: {
            //host
            host: '127.0.0.1',
            //port
            port: '3306',
            //username
            user: 'root',
            //password
            password: 'tiger',
            //database
            database: 'courseDB',
            charset: "utf8mb4"

        },
        //load into app,default is open //加载到应用程序，默认为打开
        app: true,
        //load into agent,default is close //加载到代理中，默认值为“关闭”
        agent: false,
    };



    return {
        ...config,
        ...userConfig,
    };
};
